<?php
namespace app\index\controller;

use app\index\model\Attribute;
use support\Db;
use support\Request;

class Index
{
    public function index(Request $request)
    {
        return response('hello webman');
    }

    public function view(Request $request)
    {
        return view('index/view', ['name' => 'webman']);
    }

    public function json(Request $request)
    {
        //数据表直接查询操作
        //$data = Db::table('attribute')->first();
        //模型查询数据表
        $data = Attribute::all()->toArray();
        return json(['code' => 0, 'msg' => 'ok','data'=>$data]);
    }

    public function file(Request $request)
    {
        $file = $request->file('upload');
        if ($file && $file->isValid()) {
            $file->move(public_path().'/files/myfile.'.$file->getExtension());
            return json(['code' => 0, 'msg' => 'upload success']);
        }
        return json(['code' => 1, 'msg' => 'file not found']);
    }
    
}
